import observe from "./observe"
import Dep from "./Dep"
function defineReactive(data, key, val) {
  const dep = new Dep()
  if (arguments.length == 2) {
    val = data[key] //属性值
  }
  // 对象里的对象

  let childOb = observe(val)
  Object.defineProperty(data, key, {
    enumerable: true,
    configurable: true, //属性可以被delete ,和配置
    get() {
      console.log("getget属性键", key)
      return val //相当于temp全局变量
    },
    set(newVal) {
      console.log("setset属性键" + key, newVal)
      if (val === newVal) return
      val = newVal
      childOb = observe(newVal)
      dep.notify()
    },
  })
}
export default defineReactive
